<template>
        <div>
                <van-row type="flex" justify="center">
                        <van-col>面筋登录</van-col>
                </van-row>
                <van-form @submit="onSubmit">
                        <van-field v-model="username" name="username" label="用户名" placeholder="用户名"
                                :rules="[{ required: true, message: '请填写用户名' }]" />
                        <van-field v-model="password" type="password" name="password" label="密码" placeholder="密码"
                                :rules="[{ required: true, message: '请填写密码' }]" />
                        <div style="margin: 16px;">
                                <button type="submit" class="btn">登 录</button>
                        </div>
                </van-form>
                <div style="text-align: right;margin-right: 30px;">
                        <router-link to="/register">注册账号</router-link>
                </div>
        </div>
</template>
<script>
import { loginAPI } from '@/api/user';
import request from '@/utils/request'
import { setToken } from '@/utils/storage'
import { Notify } from 'vant';
// export const login = (data) => {
//         return request.post('/login', data)
// }
export default {
        data() {
                return {
                        username: '',
                        password: '',
                };
        },
        methods: {
                async onSubmit(values) {
                        // const { data } = await login(values)
                        // setToken(data.token)
                        // this.$toast.success('登录成功')
                        // this.$router.push('/')

                        const res = await loginAPI(values)
                        console.log(res);
                        setToken(res.data.token)
                        Notify({type:"success",message:'登录成功'})
                        this.$router.push('/')
                }
        },
};
</script>
<style lang='less'  scoped>
.btn {
        width: 94%;
        height: 40px;
        border: none;
        background: #fa6d1d;
        text-align: center;
        color: #fff;
        margin: 3%;
}
</style>
